
import { Component, OnInit, Injector, AfterViewInit, OnDestroy, ViewChild, HostBinding, TemplateRef, ElementRef, ViewContainerRef, NgModuleFactory, Input, ComponentRef} from '@angular/core';
import { BehaviorSubject, of, Subject } from 'rxjs';
import { map, filter, switchMap } from 'rxjs/operators';
import { Form, FrameEvent, FrameEventBus, FrameComponent, FARRIS_DEVKIT_FRAME_PROVIDERS, ViewModel, COMMAND_HANDLERS_TOKEN, FRAME_ID, StateMachine, BindingData, Repository, UIState, NgSubscription, Declaration, EXCEPTION_HANDLER, NAMESPACE } from '@farris/devkit';
import { FARRIS_COMMAND_SERVICE_FRAME_PROVIDERS, ComponentManagerService } from '@farris/command-services';
import { KeybindingService } from '@farris/command-services';
import { ActivatedRoute, ParamMap, Router } from '@angular/router';
import { FrmI18nSettingService } from '@gsp-sys/rtf-common';
import { DomSanitizer } from '@angular/platform-browser';

import { FocusInvalidService } from '@farris/command-services';

import { BefLookupRestService, DefaultComboHttpService } from '@farris/bef';
import { ServerSideToken } from '@farris/ui-lookup';
import { ComboServerSideToken } from '@farris/ui-combo-list';
import { WizardService, FarrisPageDetailComponent } from '@farris/ui-wizard';
import { LocalizationService } from "@farris/command-services";
import { __decorate, __metadata } from 'tslib';

import { HyxxsAtqnViewmodel } from '../../viewmodels/hyxxsatqnviewmodel';
import { HyxxRepository } from '../../models/hyxxrepository';
import { LangService } from '../../lang/lang-pipe';

import { HyxxsAtqnViewmodelForm } from '../../viewmodels/form/hyxxsatqnviewmodelform';
import { HyxxsAtqnViewmodelUIState } from '../../viewmodels/uistate/hyxxsatqnviewmodeluistate';
import { hyxxAddh2o7Handler } from '../../viewmodels/handlers/hyxxaddh2o7handler';
import { hyxxRemovefpxzHandler } from '../../viewmodels/handlers/hyxxremovefpxzhandler';

@Component({
    selector: 'app-hyxxsatqncomponent',
    templateUrl: './hyxxsatqncomponent.html',
    styleUrls: ['./hyxxsatqncomponent.scss'],
    providers: [
        FARRIS_DEVKIT_FRAME_PROVIDERS,
        FARRIS_COMMAND_SERVICE_FRAME_PROVIDERS,
        { provide: FRAME_ID, useValue: 'hyxxs-atqn-component' },
        { provide: BindingData, useClass: BindingData },
        { provide: Repository, useExisting: HyxxRepository },
        LangService,
        { provide: NAMESPACE, useValue: '' },
    
        { provide: ServerSideToken, useClass: BefLookupRestService },
        { provide: ComboServerSideToken, useClass: DefaultComboHttpService },
        { provide: Form, useClass: HyxxsAtqnViewmodelForm },
        { provide: UIState, useClass: HyxxsAtqnViewmodelUIState },
        { provide: ViewModel, useClass: HyxxsAtqnViewmodel },
        { provide: EXCEPTION_HANDLER, useValue: null },
        { provide: COMMAND_HANDLERS_TOKEN, useClass: hyxxAddh2o7Handler, multi: true },
        { provide: COMMAND_HANDLERS_TOKEN, useClass: hyxxRemovefpxzHandler, multi: true },
]
})
export class HyxxsAtqnComponent extends FrameComponent implements OnInit, AfterViewInit, OnDestroy {

    @HostBinding('class')
    cls = 'f-struct-wrapper ';
    public viewModel: HyxxsAtqnViewmodel;
    lang: string ="";
    size: any = {};
    enabledLanguageList: any[] = [];
    constructor(
        private wizardSer: WizardService,
        private keybindingService: KeybindingService,
        private langService: LangService,
        private route: ActivatedRoute,
        private router: Router,
        private rootElement: ElementRef,
        private localizationService: LocalizationService,
        private frmI18nSettingService: FrmI18nSettingService,
        private focusInvalidService: FocusInvalidService,
        private stateMachine: StateMachine,
        private sanitizer: DomSanitizer,
        public injector: Injector
    ) {
        super(injector);
        this.lang = localStorage.getItem('languageCode') || "zh-CHS";
        this.viewModel.verifycationChanged.subscribe((verifyInformations: any) => {
            this.focusInvalidService.focusInvalidInput(verifyInformations, this.rootElement);
        });

        if (this.frmI18nSettingService) {
            const i18nSetting = this.frmI18nSettingService.getSetting();
            if (i18nSetting && i18nSetting.languages && i18nSetting.languages.length > 0) {
                i18nSetting.languages.forEach((item) => {
                    this.enabledLanguageList.push({
                        code: item.code,
                        name: item.name
                    });
                });
            } else {
                console.warn("get current enable languages is null. if this occurs,please ensure the form into the framework.");
                this.enabledLanguageList.push({ "code": "en", "name": "English" });
                this.enabledLanguageList.push({ "code": "zh-CHS", "name": "中文简体" });
            }
        }
    }
    ngOnInit() {
            
        if (this.keybindingService) {
            this.viewModel.keybindingMap.forEach((keyBinding, method) => {
                this.keybindingService.register(keyBinding, () => {
                    return this.viewModel[method]();
                });
            });
        }
        this.stateMachine.stateChange.subscribe(() => {
    
            const states = {
                'toolBarItem_delete': this.viewModel.stateMachine && !this.viewModel.stateMachine['canAddDetail'],
            }; 
            this.sectionsToolbarStates.next(states);
        });
        this.stateMachine.stateChange.subscribe(() => {
    
            const visibleStates = {
                'toolBarItem_delete': true,
            };
            this.sectionsToolbarVisibleStates.next(visibleStates);
        });
        this.onFormLoad(); 
    }

    ngAfterViewInit(): void {
    }

    ngOnDestroy(): void {
        // 增加表单的自我销毁
        this.context.dispose && this.context.dispose();
        this.context = null;
        this.subscription = null;
        this.declaration = null;
        this.wizardSer = null;
        this.keybindingService = null;
        this.langService = null;
        this.route = null;
        this.router = null;
        this.rootElement = null;
        this.localizationService = null;
        this.frmI18nSettingService = null;
        
        this.focusInvalidService = null;
        this.stateMachine = null;
        this.sanitizer = null;
        this.injector = null;
        this.enabledLanguageList = [];

    }

    handleSizeChange(size: any) {
        this.size = size;
    } 

    public onFormLoad() {
    } 
    tabsToolbarStates = new BehaviorSubject({});
    tabsToolbarVisibleStates = new BehaviorSubject({});
    sectionsToolbarStates = new BehaviorSubject({});
    sectionsToolbarVisibleStates = new BehaviorSubject({});
    basicFormSectionAtqn = {
        position: 'inHead',
        contents: [
            {
                id: 'toolBarItem_delete',
                disable: this.viewModel.stateMachine && !this.viewModel.stateMachine['canAddDetail'],
                visible: true,
                title: this.langService.transform("toolBarItem_delete", this.lang, "删除"),
                click: ($event) => { this.viewModel.hyxxRemovefpxz($event); },
                appearance: {
                    "class": "btn btn-secondary f-btn-ml"
                }
            }
        ]
    }
    SectionbasicformsectionatqnMainTitle = this.langService.transform("Section/basic-form-section-atqn/mainTitle", this.lang, "会员信息");
    SectionbasicformsectionatqnSubTitle = this.langService.transform("Section/basic-form-section-atqn/subTitle", this.lang, "");

    levelOfMember_6bb3d632_w38u_PlaceHolder = this.langService.transform("NumericBox/levelOfMember_6bb3d632_w38u/placeHolder", this.lang, "");
    levelOfMember6bb3d632W38uTextOptions = {
        "type": "number",
        "useThousands": true,
        "precision": 0,
    }
    code_16c18a8c_1272_PlaceHolder = this.langService.transform("TextBox/code_16c18a8c_1272/placeHolder", this.lang, "");
    name_fda60829_r2jg_PlaceHolder = this.langService.transform("TextBox/name_fda60829_r2jg/placeHolder", this.lang, "");
    remark_a5bfae00_ta9s_PlaceHolder = this.langService.transform("TextBox/remark_a5bfae00_ta9s/placeHolder", this.lang, "");
    state_c8a1e18c_27rn_PlaceHolder = this.langService.transform("TextBox/state_c8a1e18c_27rn/placeHolder", this.lang, "");
    organization_ab7841d2_0xub_PlaceHolder = this.langService.transform("TextBox/organization_ab7841d2_0xub/placeHolder", this.lang, "");
    gender_c9b82b1d_5gi4_PlaceHolder = this.langService.transform("TextBox/gender_c9b82b1d_5gi4/placeHolder", this.lang, "");
    countryOrArea_c4f879b9_dl9j_PlaceHolder = this.langService.transform("TextBox/countryOrArea_c4f879b9_dl9j/placeHolder", this.lang, "");
    location_7d2b5e9f_atm1_PlaceHolder = this.langService.transform("TextBox/location_7d2b5e9f_atm1/placeHolder", this.lang, "");
    idNumber_30140f27_8zgx_PlaceHolder = this.langService.transform("TextBox/idNumber_30140f27_8zgx/placeHolder", this.lang, "");
    levelName_f9f3cb1a_3l0s_PlaceHolder = this.langService.transform("TextBox/levelName_f9f3cb1a_3l0s/placeHolder", this.lang, "");
    privilege_f3753110_jtin_PlaceHolder = this.langService.transform("TextBox/privilege_f3753110_jtin/placeHolder", this.lang, "");
    recommandPeople_78eab758_xt7v_PlaceHolder = this.langService.transform("TextBox/recommandPeople_78eab758_xt7v/placeHolder", this.lang, "");
    phoneNumber_5073e9e4_aksd_PlaceHolder = this.langService.transform("TextBox/phoneNumber_5073e9e4_aksd/placeHolder", this.lang, "");
}